"""
@author: peng
@email: sb.peng@hzgosun.com
@file: alertDetailTest.py
@time: 2019/5/29 9:56

警情管理页面自动化用例
"""

import unittest
from time import sleep

from selenium.webdriver.common.keys import Keys

from common.functions import save_screenshot
from common.decorators import mkdir_classname, log4gs
from common.settings import TAG
from pages.alertDetailPage import alertPage

@log4gs
@mkdir_classname(TAG)
class IMSI_Test(unittest.TestCase):
    """警情管理测试"""
    @classmethod
    def setUpClass(cls):
        cls.log.info('=' * 30 + "开始警情管理功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page = alertPage('/VxManage/PoliceIncidentManage')

    @classmethod
    def tearDownClass(cls):
        cls.log.info('=' * 30 + "结束警情管理功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page.driver.quit()

    def setUp(self):
        self.log.info('>>>>>开始执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def tearDown(self):
        self.log.info('<<<<<结束执行用例：{} {}'.format(self.id(), self.shortDescription()))

    @unittest.skip
    def test_page(self):
        """举例：翻页"""
        self.log.debug("当前共有：" + self.page.turnPage.total_page +"页数据" )
        self.log.debug("当前处于第：" + self.page.turnPage.current_page + "页数据")
        self.assertEqual(self.page.turnPage.current_page, '1')
        sleep(1)
        try:
            self.assertNotEqual(self.page.turnPage.total_page, 1, msg="页数过少，无法进行翻页测试")
            self.page.turnPage.next_page.click()
            self.assertEqual(self.page.turnPage.current_page, '2')

            sleep(1)
            self.page.turnPage.next_page.click()
            self.assertEqual(self.page.turnPage.current_page, '3')

            sleep(1)
            self.page.turnPage.prev_page.click()
            self.assertEqual(self.page.turnPage.current_page, '2')

            sleep(1)
            self.page.turnPage.input.clear()
            self.page.turnPage.input.send_keys(6)
            self.page.turnPage.input.send_keys(Keys.ENTER)
            self.assertEqual(self.page.turnPage.current_page, '6')
        except Exception:
            self.log.error("当前模块最大为1页，无法进行翻页测试", exc_info=True)

    @unittest.skip
    def test_search_1(self):
        """事件名称查询"""
        self.page.searchTools.alert_input.send_keys('自动化测试物业纠纷勿动')
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(1)
        result = self.page.table.get_row("自动化测试物业纠纷勿动")
        self.assertTrue(result, "通过序列号:查到了自动化测试物业纠纷勿动")
        # self.page.searchTools.reset_btn.click()  # 点击重置按钮
        sleep(2)
        save_screenshot(self, "事件名称查询成功截图")
        sleep(2)

    @unittest.skip
    def test_search_2(self):
        """时间查询"""
        sleep(2)
        self.page.searchTools.start_time.send_keys('2019-05-01 00:00:00')
        sleep(2)
        self.page.searchTools.end_time.send_keys('2019-05-02 00:00:00')
        sleep(2)
        self.page.searchTools.search_btn.click()  # 点击搜索按钮
        sleep(1) # 点击检索按钮
        sleep(1)
        result = self.page.table.get_row("自动化测试物业纠纷勿动")
        self.assertTrue(result, "通过序列号:查到了自动化测试物业纠纷勿动")
        # self.page.searchTools.reset_btn.click()  # 点击重置按钮
        sleep(2)
        save_screenshot(self, "时间查询警情成功截图")
        sleep(2)

#没用了，暂时不写
    # @unittest.skip
    # def test_search_3(self):
    #     """警情添加"""
    #     sleep(2)
    #     self.page.table.add_btn.click()
    #     sleep(1)
    #     DropDownSelect(self.page.addAlert.add_alert_people,"发起人")
    #     sleep(2)
    #     # self.page.addAlert.add_alert_people_input.send_keys("山西省综治办")
    #     self.page.addAlert.add_alert_people.send_keys("山西省综治办")
    #     DropDownSelect(self.page.addAlert.add_alert_people, "山西省综治办")
    #
    #
    #     # self.page.addAlert.initiator_name.click()
    #     # self.page.addAlert.initiator_name_input.send_keys("山西省太原市综治中心")
    #     sleep(1)
    #     self.page.addAlert.add_alert_time.send_keys('2019-06-06 00:00:00')
    #     sleep(1)
    #     self.page.addAlert.add_alert_name.send_keys("打架斗殴")
    #     # self.page.addAlert.alert_region.click()
    #     sleep(1)
    #     DropDownSelect(self.page.addAlert.add_alert_region,"小店区太原晋泉小区")
    #     sleep(1)
    #     self.page.addAlert.add_alert_content.send_keys("小区打架斗殴")
    #     sleep(1)
    #     self.page.table.add_btn.click()
    #     self.page.addAlert.add_alert_accessory.send_keys(os.path.join(DATA_DIR, "测试人脸1.jpg"))
    #     sleep(1)
    #     self.page.addAlert.confirm.click()


if __name__ == '__main__':
    unittest.main()





